/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui2;

import entity.Menu;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import management.ManagerMenu;

/**
 *
 * @author Windows7
 */
public class GUIMenu extends javax.swing.JInternalFrame {

    /**
     * Creates new form GUIMenu
     */
    public GUIMenu() {
        try {
            initComponents();
            this.setResizable(false);
//            this.setTitle("Management menu");
             management.MyConnection.getConnection();
               // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                management.GUIInteraction.readToTable(management.ManagerMenu.sqlTbl_Menu, tblMenu);
        } catch (SQLException ex) {
            Logger.getLogger(GUIMenu.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpnSearch = new javax.swing.JPanel();
        lblDayS = new javax.swing.JLabel();
        lblErrorSearch = new javax.swing.JLabel();
        cbxDayS = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMenu = new javax.swing.JTable();
        lblMenuH = new javax.swing.JLabel();
        jpnFunction = new javax.swing.JPanel();
        btnAddMenu = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnView = new javax.swing.JButton();
        lblMenu = new javax.swing.JLabel();
        lblMenuPrice = new javax.swing.JLabel();
        txtMenu = new javax.swing.JTextField();
        lblDayOfWeek = new javax.swing.JLabel();
        cbxDayOfWeek = new javax.swing.JComboBox();
        lblMenuItem = new javax.swing.JLabel();
        txtMenuItem = new javax.swing.JTextField();
        lblErrorMenu = new javax.swing.JLabel();
        lblErrorMenuItem = new javax.swing.JLabel();
        lblErrorPrice = new javax.swing.JLabel();
        txtMenuPrice = new javax.swing.JTextField();

        setPreferredSize(new java.awt.Dimension(1024, 650));

        jpnSearch.setBorder(javax.swing.BorderFactory.createTitledBorder("Search"));
        jpnSearch.setPreferredSize(new java.awt.Dimension(150, 140));

        lblDayS.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblDayS.setText("Day Of  Week :");
        lblDayS.setPreferredSize(new java.awt.Dimension(90, 25));

        lblErrorSearch.setForeground(new java.awt.Color(255, 0, 0));
        lblErrorSearch.setPreferredSize(new java.awt.Dimension(30, 15));

        cbxDayS.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cbxDayS.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Monday", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday ", "Sunday" }));
        cbxDayS.setPreferredSize(new java.awt.Dimension(80, 25));
        cbxDayS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxDaySActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnSearchLayout = new javax.swing.GroupLayout(jpnSearch);
        jpnSearch.setLayout(jpnSearchLayout);
        jpnSearchLayout.setHorizontalGroup(
            jpnSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnSearchLayout.createSequentialGroup()
                .addContainerGap(38, Short.MAX_VALUE)
                .addComponent(lblErrorSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(86, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnSearchLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(lblDayS, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cbxDayS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );
        jpnSearchLayout.setVerticalGroup(
            jpnSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnSearchLayout.createSequentialGroup()
                .addGroup(jpnSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbxDayS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDayS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addComponent(lblErrorSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tblMenu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblMenu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblMenuMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblMenu);

        lblMenuH.setBackground(new java.awt.Color(255, 255, 255));
        lblMenuH.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        lblMenuH.setForeground(new java.awt.Color(102, 0, 102));
        lblMenuH.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblMenuH.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/menu.png"))); // NOI18N
        lblMenuH.setText(" MENU  MANAGEMENT");
        lblMenuH.setPreferredSize(new java.awt.Dimension(55, 25));

        jpnFunction.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jpnFunction.setPreferredSize(new java.awt.Dimension(15, 140));

        btnAddMenu.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        btnAddMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        btnAddMenu.setText("Add ");
        btnAddMenu.setPreferredSize(new java.awt.Dimension(90, 30));
        btnAddMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddMenuActionPerformed(evt);
            }
        });

        btnEdit.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        btnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/edit.png"))); // NOI18N
        btnEdit.setText("Edit");
        btnEdit.setPreferredSize(new java.awt.Dimension(90, 30));
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnDelete.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/exit_1.png"))); // NOI18N
        btnDelete.setText("Delete");
        btnDelete.setPreferredSize(new java.awt.Dimension(90, 30));
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnView.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        btnView.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/mnuInfo.png"))); // NOI18N
        btnView.setText("View");
        btnView.setPreferredSize(new java.awt.Dimension(90, 30));
        btnView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewActionPerformed(evt);
            }
        });

        lblMenu.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblMenu.setText("Menu :");
        lblMenu.setPreferredSize(new java.awt.Dimension(81, 15));

        lblMenuPrice.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblMenuPrice.setText("Menu Price :");

        txtMenu.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtMenu.setPreferredSize(new java.awt.Dimension(50, 25));

        lblDayOfWeek.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblDayOfWeek.setText("Day Of Week :");

        cbxDayOfWeek.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cbxDayOfWeek.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Monday", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday ", "Sunday " }));
        cbxDayOfWeek.setPreferredSize(new java.awt.Dimension(80, 25));

        lblMenuItem.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblMenuItem.setText("Menu Item :");
        lblMenuItem.setToolTipText("");
        lblMenuItem.setPreferredSize(new java.awt.Dimension(81, 15));

        txtMenuItem.setPreferredSize(new java.awt.Dimension(50, 25));

        lblErrorMenu.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
        lblErrorMenu.setForeground(new java.awt.Color(255, 0, 0));
        lblErrorMenu.setText("*");
        lblErrorMenu.setPreferredSize(new java.awt.Dimension(50, 20));

        lblErrorMenuItem.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
        lblErrorMenuItem.setForeground(new java.awt.Color(255, 0, 0));
        lblErrorMenuItem.setText("*");
        lblErrorMenuItem.setPreferredSize(new java.awt.Dimension(50, 20));

        lblErrorPrice.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
        lblErrorPrice.setForeground(new java.awt.Color(255, 0, 51));
        lblErrorPrice.setText("*");
        lblErrorPrice.setPreferredSize(new java.awt.Dimension(50, 20));

        txtMenuPrice.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtMenuPrice.setPreferredSize(new java.awt.Dimension(50, 25));

        javax.swing.GroupLayout jpnFunctionLayout = new javax.swing.GroupLayout(jpnFunction);
        jpnFunction.setLayout(jpnFunctionLayout);
        jpnFunctionLayout.setHorizontalGroup(
            jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnFunctionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDayOfWeek, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMenuPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMenuItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnFunctionLayout.createSequentialGroup()
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbxDayOfWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblErrorMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMenuItem, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblErrorMenuItem, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 187, Short.MAX_VALUE)
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jpnFunctionLayout.createSequentialGroup()
                                .addComponent(btnAddMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(76, 76, 76)
                                .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jpnFunctionLayout.createSequentialGroup()
                                .addComponent(btnEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnView, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(113, 113, 113))
                    .addGroup(jpnFunctionLayout.createSequentialGroup()
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblErrorPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMenuPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(201, 583, Short.MAX_VALUE))))
        );
        jpnFunctionLayout.setVerticalGroup(
            jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnFunctionLayout.createSequentialGroup()
                .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnFunctionLayout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblDayOfWeek)
                            .addComponent(cbxDayOfWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblErrorMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnFunctionLayout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnAddMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnFunctionLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtMenuItem, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblMenuItem, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpnFunctionLayout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblMenuPrice)
                                    .addComponent(txtMenuPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jpnFunctionLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblErrorMenuItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblErrorPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnFunctionLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jpnFunctionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnView, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(20, 20, 20))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jpnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblMenuH, javax.swing.GroupLayout.PREFERRED_SIZE, 842, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(69, 69, 69)))
                        .addGap(0, 9, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jpnFunction, javax.swing.GroupLayout.PREFERRED_SIZE, 969, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane1))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMenuH, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jpnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpnFunction, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblMenuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMenuMouseClicked
        // TODO add your handling code here:
        int i = tblMenu.getSelectedRow();
        if(i>=0){
      //  cbxDayOfWeek.setSelectedItem(String.valueOf(tblMenu.getValueAt(i, 0)));
        txtMenu.setText(String.valueOf(tblMenu.getValueAt(i, 1)));
        txtMenuItem.setText(String.valueOf(tblMenu.getValueAt(i, 2)));
        txtMenuPrice.setText(String.valueOf(tblMenu.getValueAt(i, 3)));
        }
    }//GEN-LAST:event_tblMenuMouseClicked

    private void btnAddMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddMenuActionPerformed
        // TODO add your handling code here:
        try {
            if (checkValues()) {
                Menu menu = new Menu();
                menu.setDayOfWeek(String.valueOf(cbxDayOfWeek.getSelectedItem()));
                menu.setMenu(txtMenu.getText());
                menu.setMenuItem(txtMenuItem.getText());
                menu.setMenu_Price(Float.valueOf(txtMenuPrice.getText()));
                if (management.ManagerMenu.addMenu(menu)) {
                    management.GUIInteraction.readToTable(ManagerMenu.sqlTbl_Menu, tblMenu);
                    JOptionPane.showMessageDialog(this, "Successfull");
                } else {
                    JOptionPane.showMessageDialog(this, "UnSuccessfull");
                }
                refresh();
            }
        } catch (Exception ex) {
            System.out.println(ex);
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnAddMenuActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        // TODO add your handling code here:
        try {
            if (txtMenu.getText().length() == 0 & txtMenuItem.getText().length() == 0 & txtMenuPrice.getText().length() == 0) {
                JOptionPane.showMessageDialog(this, "You don't choice any Menu to edit");
            }
            if (checkValues()) {
                int selectRow = tblMenu.getSelectedRow();
                int id = Integer.parseInt(tblMenu.getModel().getValueAt(selectRow, 0).toString());
                Menu menu = new Menu();
                menu.setMenu_Id(id);
                menu.setDayOfWeek(String.valueOf(cbxDayOfWeek.getSelectedItem()));
                menu.setMenu(txtMenu.getText());
                menu.setMenuItem(txtMenuItem.getText());
                menu.setMenu_Price(Float.valueOf(txtMenuPrice.getText()));
                if (management.ManagerMenu.updateMenu(menu)) {
                    management.GUIInteraction.readToTable(ManagerMenu.sqlTbl_Menu, tblMenu);
                    JOptionPane.showMessageDialog(this, "Successfull !");
                } else {
                    JOptionPane.showMessageDialog(this, " Don't ssssSuccessfull !");
                }
            }
            refresh();

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnEditActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed

        int selectRow = tblMenu.getSelectedRow();
        if (selectRow == -1) {
            JOptionPane.showMessageDialog(this, "You don't choice any Menu to delete");
        }
        try {
            int id = Integer.parseInt(tblMenu.getModel().getValueAt(selectRow, 0).toString());
            
            management.ManagerMenu.deleteMenu(id);
            management.GUIInteraction.readToTable(ManagerMenu.sqlTbl_Menu, tblMenu);
            
            refresh();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Delete error");
        }
    }//GEN-LAST:event_btnDeleteActionPerformed
    public void refresh() {
        cbxDayOfWeek.setSelectedIndex(0);
        txtMenu.setText("");
        txtMenuPrice.setText("");
        txtMenuItem.setText("");
        cbxDayOfWeek.setSelectedItem("");
    }

    public boolean checkValues() {

        if (!management.CheckForm.isEmpty(txtMenu.getText())) {
            lblErrorMenu.setText("Menu don't null");
            txtMenu.requestFocus();
            return false;
        }
        if (!management.CheckForm.isEmpty(txtMenuItem.getText())) {
            lblErrorMenuItem.setText("Menu Item  don't null");
            txtMenuItem.requestFocus();
            return false;
        }
        if (!management.CheckForm.isEmpty(txtMenuPrice.getText())) {
            lblErrorPrice.setText("Menu Price don't null");
            txtMenuPrice.requestFocus();
            return false;
        }
        return true;
    }

    private void btnViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewActionPerformed
        try {
            // TODO add your handling code here:
            refresh();
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            management.GUIInteraction.readToTable(management.ManagerMenu.sqlTbl_Menu, tblMenu);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }//GEN-LAST:event_btnViewActionPerformed

    private void cbxDaySActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxDaySActionPerformed
        // TODO add your handling code here:
        String searchD = String.valueOf(cbxDayS.getSelectedItem());
        try {
            management.GUIInteraction.readToTable("select Menu_Id, Menu, MenuItem, Menu_Price from Menu where DayofWeek = '" + searchD + "'", tblMenu);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_cbxDaySActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddMenu;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnView;
    private javax.swing.JComboBox cbxDayOfWeek;
    private javax.swing.JComboBox cbxDayS;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpnFunction;
    private javax.swing.JPanel jpnSearch;
    private javax.swing.JLabel lblDayOfWeek;
    private javax.swing.JLabel lblDayS;
    private javax.swing.JLabel lblErrorMenu;
    private javax.swing.JLabel lblErrorMenuItem;
    private javax.swing.JLabel lblErrorPrice;
    private javax.swing.JLabel lblErrorSearch;
    private javax.swing.JLabel lblMenu;
    private javax.swing.JLabel lblMenuH;
    private javax.swing.JLabel lblMenuItem;
    private javax.swing.JLabel lblMenuPrice;
    private javax.swing.JTable tblMenu;
    private javax.swing.JTextField txtMenu;
    private javax.swing.JTextField txtMenuItem;
    private javax.swing.JTextField txtMenuPrice;
    // End of variables declaration//GEN-END:variables
}
